﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
//using System.Diagnostics;

/// <summary>
/// ExceptionLog 的摘要说明
/// </summary>
public class Log
{
    protected static string ExceptionFileLocation = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["DataRootPath"] + "\\Log\\Exception.log");
    protected static string InfoFileLocation = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["DataRootPath"] + "\\Log\\Info.log");
    public Log()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}

    public static bool WriteException(string message)
    {
        //StreamWriter rw = File.CreateText(batFileName);
        //rw.Write(batFile);
        //rw.Flush();
        //rw.Close();
        try
        {
            StreamWriter rw = File.AppendText(ExceptionFileLocation);
            rw.WriteLine(System.DateTime.Now.ToString() + "; " + message);
            rw.Flush();
            rw.Close();
            return true;
        }
        catch(Exception ex)
        {
            Console.WriteLine(ex.Message.ToString());
            return false;
        }


    }

    public static bool WriteInfo(string info)
    {
        try
        {
            StreamWriter rw = File.AppendText(InfoFileLocation);
            rw.WriteLine(System.DateTime.Now.ToString() + "; " + info);
            rw.Flush();
            rw.Close();
            return true;
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message.ToString());
            return false;
        }
    }
}
